package com.wen.tian.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wen.tian.enums.CommonEnum;
import com.wen.tian.exception.CustomException;
import com.wen.tian.mapper.LoginMapper;
import com.wen.tian.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author tww
 * ClassName: LoginService.java、
 * createTime: 2021年01月02日 22:39:47
 **/
@Service
public class LoginService {

    @Autowired
    private LoginMapper loginMapper;

    public SysUser login(String userName, String password) {
        SysUser sysUser = loginMapper.selectOne(new QueryWrapper<SysUser>()
                .eq("user_name", userName)
                .eq("pass_word", password));
        if (null == sysUser) {
            throw new CustomException(CommonEnum.UNKNOWN_USER_OR_PASSWORD);
        }
        return sysUser;
    }

}
